import request from '@/utils/request';
var commonPrefix = process.env.commonPrefix;

export async function SpaceList(data) {
  let { pageNum, pageSize, name } = data;
  return request(
    `${commonPrefix}/v1/workspace/list/${pageSize}/${pageNum}`,
    {
      method: 'GET',
      params: {
        name,
      },
    },
    process.env.apiUrl,
  );
}

// 获取计算源列表
export async function CalculationList() {
  return request(
    `${commonPrefix}/v1/computeSource/detail/projectSpaceId/1`,
    {
      method: 'GET',
    },
    process.env.apiUrl,
  );
}

// 工作空间创建
export async function WorkSpaceCreate(data) {
  console.log(data, '工作空间创建');
  return request(
    `${commonPrefix}/v1/workspace`,
    {
      method: 'POST',
      body: JSON.stringify(data),
    },
    process.env.apiUrl,
  );
}

// 工作空间查询我的空间列表
export async function getWorkspaceList(data) {
  return request(
    `${commonPrefix}/v1/workspace/user/workspace`,
    {
      method: 'GET',
    },
    process.env.apiUrl,
  );
}

// 工作空间详情

export async function spaceDetail(data) {
  let { id } = data;
  return request(
    `${commonPrefix}/v1/workspace/detail/${id}`,
    {
      method: 'GET',
    },
    process.env.apiUrl,
  );
}

// 工作空间编辑

export async function spaceEdit(data) {
  console.log(data, '工作空间编辑');
  return request(
    `${commonPrefix}/v1/workspace`,
    {
      method: 'PUT',
      body: JSON.stringify(data),
    },
    process.env.apiUrl,
  );
}

// 工作空间删除

export async function spaceDelete(data) {
  return request(
    `${commonPrefix}/v1/workspace/id/${data.id}`,
    {
      method: 'DELETE',
      // body: JSON.stringify(data),
    },
    process.env.apiUrl,
  );
}

export async function sameName(data) {
  return request(
    `${commonPrefix}/v1/workspace/name/validator`,
    {
      method: 'GET',
      params: {
        name: data.name,
      },
    },
    process.env.apiUrl,
  );
}
